package com.example.config;

import com.example.domain.property.User;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//拦截器类
public class UserIntercetor implements HandlerInterceptor {
    //目标方法执行之前 执行
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("被拦截了....");
        User user =(User)request.getSession().getAttribute("user");
        System.out.println("拦截获取信息："+user);
        if(user==null){
            response.sendRedirect("/back/login/login.html");
            return false;    //表示不放行
        }
        return true;     //表示放行
    }
}
